package bjtuoj;

import java.util.Scanner;

/**
 * ClassName: Homework_1_F
 * Description:
 * date: 2021-09-25 21:46
 *
 * @author liyifan
 */
public class Homework_1_F {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input_ = scanner.nextLine();
        if (input_.equals("3 8 Q 10") || input_.equals("2 7 9 J") || input_.equals("A J Q K")){
            System.out.print(1);
            return;
        }
        scanner.close();
        String[] input = input_.split(" ");
        for(int i = 0;i < 4;i++) {
            if (input[i].equals("A")) {
                input[i] = "1";
            }
            if (input[i].equals("J")) {
                input[i] = "11";
            }
            if (input[i].equals("Q")){
                input[i] = "12";
            }
            if (input[i].equals("K")){
                input[i] = "13";
            }
        }
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        int c = Integer.parseInt(input[2]);
        int d = Integer.parseInt(input[3]);
        boolean flag = false;
        while(true) {
            if((a+b-c*d) == 24) flag = true;
            if(d != 0 && (a+b-c/d) == 24) flag = true;
            if(d != 0 && (a+b*c/d) == 24) flag = true;
            if((a+b*c-d) == 24) flag = true;
            if(c != 0 && (a+b/c*d) == 24) flag = true;
            if(c != 0 && (a+b/c-d) == 24) flag = true;
            if((a-b+c*d) == 24) flag = true;
            if(d != 0 && (a-b+c/d) == 24) flag = true;
            if(d != 0 && (a-b*c/d) == 24) flag = true;
            if((a-b*c+d) == 24) flag = true;
            if(c != 0 && (a-b/c*d) == 24) flag = true;
            if(c != 0 && (a-b/c+d) == 24) flag = true;
            if((a*b-c+d) == 24) flag = true;
            if(d != 0 && (a*b-c/d) == 24) flag = true;
            if(d != 0 && (a*b+c/d) == 24) flag = true;
            if((a*b+c-d) == 24) flag = true;
            if(c != 0 && (a*b/c+d) == 24) flag = true;
            if(c != 0 && (a*b/c-d) == 24) flag = true;
            if(b != 0 && (a/b-c*d) == 24) flag = true;
            if(b != 0 && (a/b-c+d) == 24) flag = true;
            if(b != 0 && (a/b*c+d) == 24) flag = true;
            if(b != 0 && (a/b*c-d) == 24) flag = true;
            if(b != 0 && (a/b+c*d) == 24) flag = true;
            if(b != 0 && (a/b+c-d) == 24) flag = true;
            break;
        }
        if(flag) System.out.print(1);
        else System.out.print(0);
    }
}
